using System.Collections.Generic;
using System.Linq;
using ExampleWebApplication.Entities;
using ExampleWebApplication.Models;
using NHibernate;
using TelerikMvcGridCustomBindingHelper.NHibernate;

namespace ExampleWebApplication.Infraestruture.Aggregates
{
    class SumUnitPriceMultipliedByUnitsOnOrderNHibernateAggregateFunction : NHibernateGridCustomBindingHelper<Product, ProductModel>.CustomAggregateFunction
    {
        public override IFutureValue<object> GetValue(IQueryOver<Product, Product> entities)
        {
            return entities.Aggregate(x => x.UnitPrice * x.Units_On_Order).Sum();
        }

        protected override object GetValueFromGroup(IEnumerable<ProductModel> @group)
        {
            return @group.Sum(x => x.UnitPrice * x.Units_OnOrder);
        }
    }
}